<?php
set_time_limit(0);
$root=preg_replace('/cron$/', '', dirname(__FILE__));

require_once($root."inc.config.php");

require_once($root."initialize.php");

if(($db_msg=cron_initialize()) !== true){

	print_r("Connection error");

}else{ 

	$db=$vars["db"];

	
		$t = @mysql_num_rows($r=mysql_query("SELECT * FROM gg_share ORDER BY uid,buy_date"));
		
		if($t<=0)
		{
			print_r("no record");
			exit;
		}
		
		$uid=0;
		$bal=0;
		while($share = mysql_fetch_assoc($r))
		{
			if($uid<>$share['uid']){
				$uid = $share['uid'];
				$bal = $share['total_unit'];
			}else{
				$bal += $share['total_unit'];
			}
			$sql = "INSERT INTO gg_member_swallet_record SET uid=".$share['uid'].",amount=".$share['total_unit'].",type='credit',bal=".$bal.",cdate='".$share['buy_date']."'";
			mysql_query($sql);
		}

	print_r("finish");
}
?>